package com.example.managemyself.ui.almanac;

import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.managemyself.R;

public class AlmanacDetailActivity extends AppCompatActivity {

    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_almanac_detail);

        initViews();
        setupWebView();
        loadAlmanacWebsite();
    }

    private void initViews() {
        webView = findViewById(R.id.webview_almanac);
    }

    private void setupWebView() {
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setDomStorageEnabled(true);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                // 页面加载完成
            }

            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                super.onReceivedError(view, errorCode, description, failingUrl);
                Toast.makeText(AlmanacDetailActivity.this, "加载失败: " + description, Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void loadAlmanacWebsite() {
        // 加载一个在线黄历网站
        webView.loadUrl("https://www.huangli.com/");
    }

    @Override
    public void onBackPressed() {
        if (webView.canGoBack()) {
            webView.goBack();
        } else {
            super.onBackPressed();
        }
    }
} 